#include "menu.h"
#include <cstdlib>

using namespace std;

void Menu::MenuWrite()
{
     cout << endl;
     cout << " 0. - Kilepes" << endl;
    cout << " 1. - Eleme?" << endl;
     cout << " 2. - Betesz" << endl;
     cout << " 3. - Kivesz" << endl;
    cout << " 4. - Metszet" << endl;
     cout << " 5. - Kiir (kiiro operator)" << endl;
     cout << " 6. - Masol (masolo konstruktor)" << endl;
     cout << " 7. - Egyenlove tesz (ertekadas operator)" << endl;
     cout << " 8. - Ures?" << endl;
}

void Menu::Run()
{
    int n = 0;
    do
    {
        MenuWrite();
        n = read_int("\n>>>> ","Egy 0 es 8 kozti egesz szamot kerek!",toEight);
        switch(n)
        {
            case 1: // eleme?
                int e;
                e = read_int("Kerem az elem erteket: ","Egesz szamot!");
                system("cls");
                if(h1.eleme(e) == true)
                {
                    cout << "A(z) " << e << " eleme a h1 halmaznak." << endl;
                }
                else
                {
                    cout << "A(z) " << e << " nem eleme a h1 halmaznak." << endl;
                }
                break;
            case 2: // betesz
                e = read_int("Kerem az elem erteket: ","Egesz szamot!");
                h1.betesz(e);
                system("cls");
                break;
            case 3: // kivesz
                e = read_int("Kerem az elem erteket: ","Egesz szamot!");
                try
                {
                    system("cls");
                    h1.kivesz(e);
                    cout << "A(z) " << e << " elemet kivettuk a halmazbol" << endl;
                }
                catch (halmaz::exceptions st_Ex)
                {
                    system("cls");
                    if(st_Ex == halmaz::NO_ELEM_IN) cout << "Nincs benne ez az elem a halmazban!\n";
                }
                break;
            case 4: // metszet
                system("cls");
                cout << "h1 elemei: " << h1 << endl;
                cout << "h2 elemei: " << h2 <<endl;
                h3 = h3.metszet(h1, h2);
                cout << "Metszetuk (h3): " << h3 << endl;
                break;
            case 5: // kiir
                system("cls");
                cout << "h1 elemei: " << h1 << endl;
                cout << "h2 elemei: " << h2 << endl;
                cout << "h3 elemei: " << h3 << endl;
                break;
            case 6: // copy konstruktor
                {
                halmaz h4(h1);
                system("cls");
                cout << "h1 elemei (amit lemasoltunk): " << h1 << endl;
                cout << "h4 elemei (amibe lemasoltuk): " << h4 << endl;
                break;
                }
            case 7: // ertekadas operator
                {
                h2 = h1;
                system("cls");
                cout << "h1 (aminek erteket adtunk): " << h1 << endl;
                cout << "h2 (amit ertekul adtunk): " << h2 << endl;
                break;
                }
            case 8: // ures?
                system("cls");
                if(h1.ures())
                    cout << "Ures a h1." << endl;
                else
                    cout << "Nem ures a h1." << endl;
            }
    } while(n!=0);
}

bool all(int n) { return true; }
bool toEight(int n) { return (n >= 0 && n < 9); }
int read_int(const string &msg, const string &err, bool check(int))
{
    int n;
    bool hiba;
    string tmp;
    do{
        cout << msg;
        string str;
        cin >> n;
        hiba = cin.fail() || !check(n);
        if(hiba)
        {
            cout << err << endl;
            cin.clear(); getline(cin, tmp);
        }
    }while(hiba);
    getline(cin, tmp);

    return n;
}






















/*
#include "halmaz.h"
#include "menu.h"
#include <iostream>
#include <cstdlib>

using namespace std;

void Menu::Futtatas()
{
    int c = 0;
    do
    {
        MenuKiiratas();
        cin >> c;
        switch(c)
        {
           case 1: Betesz(); break;
           case 2: Kivesz(); break;
           case 3: Ures(); break;
           case 4: Eleme(); break;
           case 5: Metszet(); break;
           //case 0: Kilepes); break;
        }
    }while(c!=0);
}

void Menu::MenuKiiratas()
{
     cout << endl << endl;
     cout << "1 Betesz()" << endl;
     cout << "2 Kivesz()" << endl;
     cout << "3 Ures()" << endl;
     cout << "4 Eleme()" << endl;
     cout << "5 Metszet()" << endl;
     cout << "0 Kilepes" << endl;
     cout << endl;
}

void Menu::Betesz()
{

}

void Menu::Kivesz()
{

}

void Menu::Ures()
{

}

void Menu::Eleme()
{

}

void Menu::Metszet()
{

}

int read_int(const string &msg, const string &err, bool check(int))
{
    int n;
    bool hiba;
    string tmp;
    do{
        cout << msg;
        string str;
        cin >> n;
        hiba = cin.fail() || !check(n);
        if(hiba) {
            cout << err << endl;
            cin.clear(); getline(cin, tmp);
        }
    }while(hiba);
    getline(cin, tmp);

    return n;
}
*/
